package by.bsuir.chess.validators
{
	import by.bsuir.chess.enums.Color;
	import by.bsuir.chess.models.GameModel;
	import by.bsuir.chess.vo.Piece;

	public class BoardStateValidator
	{
		private static var model : GameModel = GameModel.inst;

		public static function validate(state : Array) : StateValidationResult
		{
			var res : StateValidationResult = new StateValidationResult();

			var whiteKing : Piece = model.getKing(Color.WHITE);
			var blackKing : Piece = model.getKing(Color.BLACK);
			var piece : Piece;

			//check for CHECK
			for each (piece in model.pieces)
			{
				if(piece.color == Color.WHITE && piece.getMoves().contains(blackKing.position))
				{
					res.isCheck = true;
					res.victimColor |= Color.BLACK;
				}
				if(piece.color == Color.BLACK && piece.getMoves().contains(whiteKing.position))
				{
					res.isCheck = true;
					res.victimColor |= Color.WHITE;
				}
			}

			res.isMate = false;
			return res;
		}
	}
}
